//
// Created by xili on 2024/8/7 21:11.
// Go big or go home.
//
#include <vector>
#include <queue>
#include <cmath>

using namespace std;

class Solution {
public:
    long long pickGifts(vector<int> &gifts, int k) {
        priority_queue<long long> pq;
        for (auto &item: gifts) {
            pq.push(item);
        }
        while (k) {
            pq.push(sqrt(pq.top()));
            pq.pop();
            k--;
        }
        long long ans = 0;
        while (!pq.empty()) {
            ans += pq.top();
            pq.pop();
        }
        return ans;
    }
};